{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 大模型本身是没有上下文记忆的",
   "id": "5254900f7a22f727"
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "from langchain_core.messages import SystemMessage, HumanMessage, AIMessage\n",
    "import os\n",
    "\n",
    "os.environ['OPENAI_BASE_URL'] = 'https://vip.apiyi.com/v1'\n",
    "os.environ['OPENAI_API_KEY'] = 'sk-xU64G4hXJ4L47ko3764958119dB245D2BdEcE528767dA1Da'\n",
    "\n",
    "chat_model = ChatOpenAI(model=\"gpt-4o-mini\")\n",
    "\n",
    "system_message = SystemMessage(content=\"我是人工只能助手，我叫小智\")\n",
    "human_message = HumanMessage(content=\"猫王是一只猫吗?\")\n",
    "\n",
    "messages = [system_message, human_message]\n",
    "\n",
    "response = chat_model.invoke(messages)\n",
    "print(response.content)\n",
    "\n",
    "response1 = chat_model.invoke(\"你叫什么名字?\")\n",
    "print(response1.content)"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 测试",
   "id": "d92fa8c1309e346a"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "from langchain_core.messages import SystemMessage, HumanMessage\n",
    "import os\n",
    "\n",
    "os.environ['OPENAI_BASE_URL'] = 'https://vip.apiyi.com/v1'\n",
    "os.environ['OPENAI_API_KEY'] = 'sk-xU64G4hXJ4L47ko3764958119dB245D2BdEcE528767dA1Da'\n",
    "\n",
    "chat_model = ChatOpenAI(model=\"gpt-4o-mini\")\n",
    "\n",
    "system_message = SystemMessage(content=\"我是人工只能助手，我叫小智\")\n",
    "human_message1 = HumanMessage(content=\"猫王是一只猫吗?\")\n",
    "human_message2 = HumanMessage(content=\"你叫什么名字?\")\n",
    "\n",
    "messages = [system_message, human_message1, human_message2]\n",
    "\n",
    "response = chat_model.invoke(messages)\n",
    "print(response.content)"
   ],
   "id": "991ba065d63fd924",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "测试2",
   "id": "bfeba883aff80f0f"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-22T07:34:05.845654Z",
     "start_time": "2025-09-22T07:34:04.593409Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "from langchain_core.messages import SystemMessage, HumanMessage, AIMessage\n",
    "import os\n",
    "\n",
    "os.environ['OPENAI_BASE_URL'] = 'https://vip.apiyi.com/v1'\n",
    "os.environ['OPENAI_API_KEY'] = 'sk-xU64G4hXJ4L47ko3764958119dB245D2BdEcE528767dA1Da'\n",
    "\n",
    "chat_model = ChatOpenAI(model=\"gpt-4o-mini\")\n",
    "\n",
    "messages = [\n",
    "    SystemMessage(content=\"我是人工只能助手，我叫小智\"),\n",
    "    HumanMessage(content=\"猫王是一只猫吗?\"),\n",
    "    AIMessage(content=\"猫王不是猫\"),\n",
    "    HumanMessage(content=\"你叫什么名字?\")\n",
    "]\n",
    "\n",
    "response = chat_model.invoke(messages)\n",
    "print(response.content)"
   ],
   "id": "cab8f834055a3a09",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我叫小智。你有什么问题想问我吗？\n"
     ]
    }
   ],
   "execution_count": 7
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
